package com.lxk.controller;

import com.lxk.service.UtilService;
import com.lxk.vo.WangUploadModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author JohnSoybean
 * @create 2020/3/26 11:06
 * @description
 */
@Controller
public class UtilController {

    @Autowired
    private UtilService us;

    /**
     * 富文本编辑器上传图片接口
     * @param req
     * @return
     */
    @PostMapping("/upload/picture")
    @ResponseBody
    public WangUploadModel uploadModel(HttpServletRequest req, MultipartFile file) {
        WangUploadModel model = new WangUploadModel();
        try {
            String url = us.uploadPicture(file);
            model.setErrno(0);
            List data = new ArrayList();
            data.add(url);
            model.setData(data);
        }catch (Exception e){
            model.setErrno(1);
        }
        return model;
    }
}
